package com.gzist.elderlyserviceplatform.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzist.elderlyserviceplatform.common.Result;

import com.gzist.elderlyserviceplatform.entity.dto.ListQueryPageDTO;
import com.gzist.elderlyserviceplatform.entity.po.Announcement;
import com.gzist.elderlyserviceplatform.entity.vo.HomePageAnnouncementVO;
import com.gzist.elderlyserviceplatform.service.AnnouncementService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 公告信息表
 */
@RestController
@Tag(name = "公告信息管理")
@RequestMapping("/api/admin/announcement")
@RequiredArgsConstructor
public class AnnouncementControllerA {


    private final AnnouncementService announcementService;

    @PostMapping("/add")
    @Operation(summary = "公告信息添加")
    public Result add(@RequestBody Announcement announcement) {
        announcementService.save(announcement);
        return Result.success("添加成功");
    }

    @PostMapping("/list")
    @Operation(summary = "公告信息查询列表接口")
    public Result<Page<Announcement>> list(@RequestBody ListQueryPageDTO listQueryPageDTO) {
        return Result.success(announcementService.list(listQueryPageDTO), "查询成功");
    }

    @GetMapping("/detail/{id}")
    @Operation(summary = "公告信息单个查询")
    public Result<Announcement> detail(@PathVariable String id) {
        return Result.success(announcementService.getById(id), "查询成功");
    }

    @PostMapping("/update")
    @Operation(summary = "公告信息修改接口")
    public Result update(@RequestBody Announcement announcement) {
        announcementService.update(announcement);
        return Result.success("修改成功");
    }

    @GetMapping("/homePageList")
    @Operation(summary = "首页公告列表查询接口", description = "首页公告信息查询列表接口")
    public Result<List<HomePageAnnouncementVO>> getHomePageList() {
        return Result.success(announcementService.getHomePageList(), "查询成功");
    }

    @PostMapping("/delete/{id}")
    @Operation(summary = "公告信息删除")
    public Result delete(@PathVariable String id) {
        announcementService.removeById(id);
        return Result.success("删除成功");
    }

    @PostMapping("/batchDelete")
    @Operation(summary = "公告信息批量删除")
    public Result deleteBatch(
            @RequestBody
            @Parameter(description = "公告信息id集") String[] ids
    ) {
        announcementService.removeByIds(Arrays.asList(ids));
        return Result.success("删除成功");
    }
}